var a = getApp(), e = require("../../339469457B99569C55F201426D89DBD0.js"), t = require("../../38034BA77B99569C5E6523A090A9DBD0.js"), s = e.getImgCheckurl(), n = e.getBdOcrUrl();

Page({
    data: {
        array: [ "通用OCR", "身份证OCR（正面）", "身份证OCR（背面）", "银行卡OCR", "手写字体识别", "通用OCR（含位置信息版）", "通用OCR（含生僻字版）", "通用OCR（高精度版）", "通用OCR（含位置高精度版）", "驾驶证OCR", "行驶证OCR", "网图OCR", "营业执照OCR", "车牌OCR", "彩票OCR", "公式OCR", "通用票据OCR", "表格OCR（提交）", "表格OCR（获取）" ],
        index: 0,
        words: "",
        wordsesultNum: "",
        address: "",
        sex: "",
        birth: "",
        idCardNum: "",
        imageStatus: "",
        name: "",
        nation: "",
        riskType: "",
        authority: "",
        expiryDate: "",
        issueDate: "",
        bankCardNumber: "",
        bankCardType: "",
        bankName: "",
        userInfo: {},
        backUserInfo: {},
        hasUserInfo: !1,
        openId: "",
        nickName: "",
        canIUse: wx.canIUse("button.open-type.getUserInfo"),
        info: "",
        token: null
    },
    bindPickerChange: function(a) {
        this.setData({
            index: a.detail.value,
            words: "",
            wordsesultNum: "",
            address: "",
            birth: "",
            idCardNum: "",
            imageStatus: "",
            name: "",
            nation: "",
            riskType: "",
            authority: "",
            expiryDate: "",
            issueDate: "",
            bankCardNumber: "",
            bankCardType: "",
            info: "",
            bankName: ""
        }), console.log("picker发送选择改变，携带值为", a.detail.value);
        var e = a.detail.value;
        console.info(e), "0" != e && "1" != e && "2" != e && "3" != e && "4" != e && wx.showModal({
            title: "温馨提示",
            showCancel: !1,
            content: "目前只有通用OCR,银行卡识别,身份证正反面识别,手写字体识别可用 ",
            success: function(a) {
                this.setData({
                    ocrindex: 0
                });
            },
            fail: function(a) {
                this.setData({
                    ocrindex: "0"
                });
            }
        });
    },
    copyTEXT: function(a) {
        var e = this, t = e.data.index, s = "";
        s = "0" == t || "4" == t ? e.data.words : "1" == t ? e.data.name + "\n" + e.data.sex + "\n" + e.data.nation + e.data.birth + "\n" + e.data.address + "\n" + e.data.idCardNum : "2" == t ? e.data.authority + "\n" + e.data.expiryDate + "\n" + e.data.issueDate : "3" == t ? e.data.bankName + "\n" + e.data.bankCardType + "\n" + e.data.bankCardNumber : "疯狂给小帅丶打Call", 
        wx.setClipboardData({
            data: s,
            success: function(a) {
                wx.showModal({
                    title: "提示",
                    content: "复制成功",
                    showCancel: !1
                });
            }
        });
    },
    clear: function() {
        var a = this;
        console.info(a), this.setData({
            words: "",
            wordsesultNum: "",
            address: "",
            birth: "",
            sex: "",
            idCardNum: "",
            imageStatus: "",
            name: "",
            nation: "",
            riskType: "",
            authority: "",
            expiryDate: "",
            issueDate: "",
            bankCardNumber: "",
            bankCardType: "",
            info: "",
            bankName: ""
        });
    },
    uploads: function() {
        var a = this;
        console.info(a);
        var e = a.data.index;
        console.info(e), "0" != e && "1" != e && "2" != e && "3" != e && "4" != e ? wx.showModal({
            title: "友情提示",
            showCancel: !1,
            content: "目前只有通用OCR,银行卡识别,身份证正反面识别,手写字体识别可用 ",
            success: function(e) {
                a.setData({
                    ocrindex: 0
                });
            },
            fail: function(e) {
                a.setData({
                    ocrindex: 0
                });
            }
        }) : (console.info(e), wx.chooseImage({
            count: 1,
            sizeType: [ "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                a.setData({
                    img: t.tempFilePaths[0],
                    words: "",
                    sex: "",
                    wordsesultNum: "",
                    address: "",
                    birth: "",
                    idCardNum: "",
                    imageStatus: "",
                    name: "",
                    nation: "",
                    riskType: "",
                    authority: "",
                    expiryDate: "",
                    issueDate: "",
                    bankCardNumber: "",
                    bankCardType: "",
                    info: "",
                    bankName: ""
                }), setTimeout(function() {
                    wx.showLoading({
                        title: "智能提取中...",
                        mask: !0
                    });
                }, 500), wx.uploadFile({
                    url: s,
                    filePath: t.tempFilePaths[0],
                    header: {
                        "content-type": "multipart/form-data"
                    },
                    name: "file",
                    formData: {
                        code: "XSYD"
                    },
                    success: function(s) {
                        var o = JSON.parse(s.data);
                        "0" == o.errcode ? wx.uploadFile({
                            url: n,
                            filePath: t.tempFilePaths[0],
                            header: {
                                "content-type": "multipart/form-data"
                            },
                            name: "file",
                            formData: {
                                ocrtype: e,
                                openId: a.data.openId,
                                nickName: a.data.nickName
                            },
                            success: function(e) {
                                wx.hideLoading(), console.info(e);
                                var t = e.data, s = JSON.parse(t);
                                "0" == s.code ? "ocr" == s.ocrType ? a.setData({
                                    words: s.words,
                                    wordsesultNum: s.wordsesultNum
                                }) : "idcardf" == s.ocrType ? a.setData({
                                    address: s.address,
                                    birth: s.birth,
                                    idCardNum: s.idCardNum,
                                    imageStatus: s.imageStatus,
                                    name: s.name,
                                    nation: s.nation,
                                    riskType: s.riskType,
                                    sex: s.sex
                                }) : "idcardb" == s.ocrType ? a.setData({
                                    authority: s.authority,
                                    expiryDate: s.expiryDate,
                                    imageStatus: s.imageStatus,
                                    issueDate: s.issueDate,
                                    riskType: s.riskType
                                }) : "bank" == s.ocrType ? a.setData({
                                    bankCardNumber: s.bankCardNumber,
                                    bankCardType: s.bankCardType,
                                    bankName: s.bankName
                                }) : "handwriting" == s.ocrType ? a.setData({
                                    words: s.words,
                                    wordsesultNum: s.wordsesultNum
                                }) : a.setData({
                                    info: "未能识别出文字"
                                }) : "5" == s.code ? a.setData({
                                    info: "未能识别出相关内容"
                                }) : a.setData({
                                    info: "Sorry 小程序远走高飞了"
                                });
                            },
                            fail: function(e) {
                                wx.hideLoading(), console.log(e), a.setData({
                                    info: "小程序离家出走了稍后再试"
                                });
                            }
                        }) : "87014" == o.errcode ? (wx.hideLoading(), wx.showModal({
                            content: "存在敏感内容，请更换图片",
                            showCancel: !1,
                            confirmText: "明白了"
                        }), a.setData({
                            img: null
                        })) : (wx.hideLoading(), wx.showModal({
                            content: "其他错误，稍后再试",
                            showCancel: !1,
                            confirmText: "明白了"
                        }));
                    }
                });
            }
        }));
    },
    onShareAppMessage: function() {
        return {
            title: "OCR识别",
            path: "/pages/ocr/ocr",
            imageUrl: "https://www.xsshome.cn/timg.jpg",
            success: function(a) {
                "shareAppMessage:ok" == a.errMsg && wx.showToast({
                    title: "分享成功",
                    icon: "success",
                    duration: 500
                });
            },
            fail: function(a) {
                "shareAppMessage:fail cancel" == a.errMsg && wx.showToast({
                    title: "分享取消",
                    icon: "loading",
                    duration: 500
                });
            }
        };
    },
    onLoad: function() {
        var e = this, s = a.data.openId;
        this.setData({
            openId: s
        }), t.tokenRequest({
            success: function(a) {
                e.setData({
                    token: a.access_token
                });
            }
        });
    }
});